import React, { Component } from 'react'
import "./index.scss"
import { Layout, Menu ,Breadcrumb} from 'antd';
import { DesktopOutlined, PieChartOutlined, FileOutlined, TeamOutlined, UserOutlined } from '@ant-design/icons';
import { ajax } from '../../api';
import mobxdata from "../../mobx/data"
import MyHead from './myhead'
import MyMenu from './mymenu'
import { Switch, Route, Redirect } from "react-router-dom"
import lazyload from '../../utils/lazyload';
const { Header, Content, Footer, Sider } = Layout;
export default class Main extends Component {
    componentDidMount(){
        ajax.getuserinfo()
        .then(res=>{
            if(res.code==200){
                mobxdata.changeuserinfo(res.result)
            }else if(res.code==3000){
                this.props.history.push("/login")
            }
        })
    }
    render() {
        console.log(mobxdata);
        return (
            <div className="main">
                <Layout style={{width:'100%',height:'100%',minHeight: '100vh',display:'flex',flexDirection:"row"}}>
                    <div >
                        <MyMenu history={this.props.history} /> 
                    </div>

                    <Layout style={{flex:1,height:'100vh',display:'flex'}}>
                        <div style={{padding:'0  0 0 20px'}}>
                            <MyHead userinfo={mobxdata.userinfo} history={this.props.history}/>
                        </div>
                        <Layout style={{padding:"0 20px 0px",flex:1}}>
                            <Breadcrumb style={{ margin: '16px 0' }}>
                            </Breadcrumb>
                            <Content  style={{ padding: 20, minHeight: 360,margin:0, overflow:'auto', height:'100%', background:"#fff" }}>
                                <Switch>
                                    <Route path="/main" exact render={()=>(<Redirect to="/main/home" /> )} />
                                    <Route path="/main/home" exact component={lazyload(()=>import("../home"))} />
                                    
                                    <Route path="/main/user" component={
                                        ()=>(
                                            <Switch>
                                                <Route path="/main/user" exact render={()=>(<Redirect to="/main/user/list" /> )} />
                                                <Route path="/main/user/list"  component={lazyload(()=>import("../users"))  }  />
                                                <Route path="/main/user/infolist"  component={lazyload(()=>import("../users/infolist"))  }  />
                                                <Route path="/main/user/fenxi"  component={lazyload(()=>import("../users/fenxi"))  }  />
                                            </Switch>
                                        )
                                    }></Route>
                                    <Route path="/main/updatePwd"  component={lazyload(()=>import("./updatePwd"))  }  />
                                    <Route path="/main/salary" component={
                                        ()=>(
                                            <Switch>
                                                <Route path="/main/salary" exact render={()=>(<Redirect to="/main/salary/list" /> )} />
                                                <Route path="/main/salary/list"  component={lazyload(()=>import("../salary"))  }  />
                                                <Route path="/main/salary/fenxi"  component={lazyload(()=>import("../salary/fenxi"))  }  />
                                            </Switch>
                                        )
                                    }></Route>
                                    <Route path="/main/notice" component={
                                        ()=>(
                                            <Switch>
                                                <Route path="/main/notice" exact render={()=>(<Redirect to="/main/notice/list" /> )} />
                                                <Route path="/main/notice/list"  component={lazyload(()=>import("../notice/list"))  }  />
                                                <Route path="/main/notice/create"  component={lazyload(()=>import("../notice/create"))  }  />
                                                <Route path="/main/notice/update/:aid"  component={lazyload(()=>import("../notice/update"))  }  />
                                            </Switch>
                                        )
                                    }></Route>

                                    <Route path="/main/advise" component={
                                        ()=>(
                                            <Switch>
                                                <Route path="/main/advise" exact render={()=>(<Redirect to="/main/advise/list" /> )} />
                                                <Route path="/main/advise/list"  component={lazyload(()=>import("../advise/list"))  }  />
                                                <Route path="/main/advise/create"  component={lazyload(()=>import("../advise/create"))  }  />
                                                <Route path="/main/advise/update"  component={lazyload(()=>import("../advise/update"))  }  />
                                                <Route path="/main/advise/fenxi"  component={lazyload(()=>import("../advise/fenxi"))  }  />
                                                <Route path="/main/advise/detail"  component={lazyload(()=>import("../advise/detail"))  }  />
                                            </Switch>
                                        )
                                    }></Route>
                
                                    <Route path="/main/mine" exact component={lazyload(()=>import("../mine"))} />
                                    <Route path="/main/map" exact component={lazyload(()=>import("../map"))} />
                                    <Route  exact render={()=>(<Redirect to="/main/home" /> )}  />
                                </Switch>
                            </Content>
                            <Footer style={{ textAlign: 'center',padding:10 }}>海底捞后台管理系统 ©2010 Created by 🐻</Footer>
                        </Layout>
                    </Layout>
                </Layout>
            </div>
        )
    }
}
